package cn.home.fenni.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.fenni.domain.HomeServiceItem;
import cn.home.fenni.service.IHomeServiceItemService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 服务项目管理Controller
 * 
 * @author homedoctor
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/item/item")
public class HomeServiceItemController extends BaseController
{
    @Autowired
    private IHomeServiceItemService homeServiceItemService;

    /**
     * 查询服务项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeServiceItem homeServiceItem)
    {
        startPage();
        List<HomeServiceItem> list = homeServiceItemService.selectHomeServiceItemList(homeServiceItem);
        return getDataTable(list);
    }

    /**
     * 导出服务项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:export')")
    @Log(title = "服务项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeServiceItem homeServiceItem)
    {
        List<HomeServiceItem> list = homeServiceItemService.selectHomeServiceItemList(homeServiceItem);
        ExcelUtil<HomeServiceItem> util = new ExcelUtil<HomeServiceItem>(HomeServiceItem.class);
        util.exportExcel(response, list, "服务项目管理数据");
    }

    /**
     * 获取服务项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(homeServiceItemService.selectHomeServiceItemByItemId(itemId));
    }

    /**
     * 新增服务项目管理
     */
    @PreAuthorize("@ss.hasPermi('item:item:add')")
    @Log(title = "服务项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeServiceItem homeServiceItem)
    {
        return toAjax(homeServiceItemService.insertHomeServiceItem(homeServiceItem));
    }

    /**
     * 修改服务项目管理
     */
    @PreAuthorize("@ss.hasPermi('item:item:edit')")
    @Log(title = "服务项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeServiceItem homeServiceItem)
    {
        return toAjax(homeServiceItemService.updateHomeServiceItem(homeServiceItem));
    }

    /**
     * 删除服务项目管理
     */
    @PreAuthorize("@ss.hasPermi('item:item:remove')")
    @Log(title = "服务项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(homeServiceItemService.deleteHomeServiceItemByItemIds(itemIds));
    }
}
